package com.siwei.mes.entity.experiment;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 受检台账(ExperimentTested)实体类
 *
 * @author linzi
 * @since 2024-07-26 16:58:47
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_experiment_tested")
@ApiModel(value = "ExperimentTested", description = "受检台账")
public class ExperimentTested implements Serializable {
    private static final long serialVersionUID = -53237441635475066L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "受检台账主键ID", name = "id")
    @NotNull(groups = {UpdateGroup.class}, message = "受检台账主键Id为空")
    private Long id;
    /**
     * 检查单位
     */
    @Column(name = "inspect_company")
    @ApiModelProperty(value = "检查单位", name = "inspectCompany")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "检查单位为空")
    private String inspectCompany;
    /**
     * 受检单位
     */
    @Column(name = "tested_company")
    @ApiModelProperty(value = "受检单位", name = "testedCompany")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "受检单位为空")
    private String testedCompany;
    /**
     * 检查日期
     */
    @Column(name = "inspect_time")
    @ApiModelProperty(value = "检查日期", name = "inspectTime")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "检查日期为空")
    private Date inspectTime;
    /**
     * 检查内容
     */
    @Column(name = "inspect_content")
    @ApiModelProperty(value = "检查内容", name = "inspectContent")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "检查内容为空")
    private String inspectContent;
    /**
     * 检查汇总
     */
    @Column(name = "inspect_collect")
    @ApiModelProperty(value = "检查汇总", name = "inspect_ collect")
    private String inspectCollect;
    /**
     * 检查结果
     */
    @Column(name = "inspect_result")
    @ApiModelProperty(value = "检查结果", name = "inspectResult")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "检查结果为空")
    private String inspectResult;
    /**
     * 纠正措施
     */
    @Column(name = "corrective_action")
    @ApiModelProperty(value = "纠正措施", name = "correctiveAction")
    private String correctiveAction;
    /**
     * 附件  多个用逗号隔开
     */
    @Column(name = "attachments")
    @ApiModelProperty(value = "附件  多个用逗号隔开", name = "attachments")
    private String attachments;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    @Transient
    @ApiModelProperty(value = "开始时间")
    private String startTime;
    @Transient
    @ApiModelProperty(value = "结束时间")
    private String endTime;

    public ExperimentTested init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date()).setIsDel(0);
        }
        return this;
    }
}
